import { useObservable } from 'rxjs-hooks';
import { interval } from 'rxjs';
import { map } from 'rxjs/operators';
import { useEffect } from 'react';
import { Requests } from '@/utils/requests';

export const indexViewModel = async () => {
  const model = await Requests.defaults.http('post', '/v1/api/douBanTop', {
    header: {
      Authorization:
        'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6IjU3MDc3OTI4NEBxcS5jb20iLCJ1c2VyX2lkIjoxLCJzdGFydF90aW1lIjoxNjA3OTEyMDgxLCJlbmRfdGltZSI6MTYxNTExMjA4MX0.UYIPnbvs4oMHE0sEkZ39TV9ztVOgH1tN7yISH1eAyxA',
    },
    callBack: {
      success: (response) => {
        return interval(500).pipe(map((val) => val * 5));
      },
    },
  });
  if (model.code == 200) {
    return interval(500).pipe(map((val) => val * 10));
  }
  return interval(500).pipe(map((val) => val * 3));
};

export const setCount = (data: any) => {
  return data;
};

// export const indexViewModel = ()=> {
//   // useEffect(()=>{
//   Request.defaults.http("get", "47.90.62.114:8086/bsl_web/base/countryList.do", {
//     callback: {
//       success: (response)=>{
//         return response.data
//       }
//     }
//   });
// });
//
//   Request.defaults.http("post", "/v1/api/douBanTop", {
//     header: {
//       "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6IjU3MDc3OTI4NEBxcS5jb20iLCJ1c2VyX2lkIjoxLCJzdGFydF90aW1lIjoxNjA3OTEyMDgxLCJlbmRfdGltZSI6MTYxNTExMjA4MX0.UYIPnbvs4oMHE0sEkZ39TV9ztVOgH1tN7yISH1eAyxA"
//     },
//     callback: {
//       success: (response)=>{
//         interval(500).pipe(map((val) => val * 3))
//       }
//     }
//   });
// }
